package com.kgc.manager.controller;

import com.kgc.entity.TbContentCategory;
import com.kgc.manger.service.ContentCatService;
import com.kgc.utils.ItripResult;
import com.kgc.utils.ResultTable;
import com.kgc.utils.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller

public class ContentCatController {

    @Autowired
    private ContentCatService contentCatService;

    @RequestMapping("listCat1")
    @ResponseBody
    public ResultTable findAll(){
           List<TbContentCategory> list=contentCatService.findAll();
        ResultTable resultTable=new ResultTable();
        resultTable.setCode(0);;
        resultTable.setCount(list.size());
        resultTable.setData(list);
        return resultTable;
    }


    //contentCat/list

    @RequestMapping("listCat")
    @ResponseBody
    public List<TreeNode> listCat(){

        return contentCatService.listCat();
    }

    //增加
    @RequestMapping("/contentcat/add")
    @ResponseBody
    public ItripResult addCat(Long pid,String name){

        return contentCatService.addContentCategory(pid,name);
    }
    //修改
    @RequestMapping("/contentcat/update")
    @ResponseBody
    public ItripResult updateCat(Long id,String name){

        return contentCatService.updateContentCategory(id,name);
    }
    //删除
    @RequestMapping("/contentcat/del")
    @ResponseBody
    public ItripResult deleteCat(Long id){

        return contentCatService.deleteContentCategory(id);
    }
}
